<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\WheelModel;
class WheelController extends Controller
{
    public function wheelAdd(){

    	return view("admin/wheelAdd");
    }

    public function wheelCreate(Request $request){

    	$data=$request->except('_token');
    	$wheel_img=request()->file('wheel_img');
    	if(!$request->hasFile('wheel_img')){
    		echo "必须上传文件!";die;
    	}
    	$ext=$wheel_img->getClientOriginalExtension();//获取后缀名
    	$filename=md5(uniqid()).".".$ext;//获取文件名拼接后缀名
    	$path=$wheel_img->storeAs('img',$filename);
    	//dd($path);
    	$data['wheel_img']=$path;

    	$res=WheelModel::create($data);

    	if($res){

    		return redirect("admin/wheelIndex");
    	}
    }


    public function wheelIndex(){

    	$data=WheelModel::get();

    	return view("admin/wheelIndex",['data'=>$data]);
    }


    // 单选按钮即点即改
   public function changevalue(){
    $value=request()->input('value');
    $field=request()->input('field');
    $wheel_id=request()->input('wheel_id');
    
    //条件
    $where=[
    ['wheel_id','=',$wheel_id]
    ];
    //修改的数组
    $date=[$field=>$value];

    
    $res=WheelModel::where($where)->update($date);
    if($res){
      echo '1';
    }else{
      echo '2';
    }
}
}